<%@ taglib uri="/tags/struts-html" prefix="html" %>
<%@ taglib uri="/tags/struts-tiles" prefix="tiles" %>
<%@ taglib uri="/tags/struts-bean" prefix="bean" %>
<%@ taglib prefix="fmt" uri="http://java.sun.com/jstl/fmt" %>
<%@ taglib prefix="c" uri="http://java.sun.com/jstl/core" %>
<%@ taglib uri="/WEB-INF/tld/security.tld" prefix="s" %>

<fmt:setBundle basename="messages"/>
<script type="text/javascript" language="javascript">
	function submitCustomerFutureQuery(form, orderField, orderType){
		form.orderField.value = orderField;
		form.orderType.value = orderType;
		form.submit();
	}
	function submitForm(form){
		form.submit();
	}
</script>
<html:form action="/searchCustomerFuturePurchaseQuery" method="POST">
	<table width="100%">
		<tr>
			<td>
				<html:hidden property="orderField"/>
				<html:hidden property="orderType"/>
				<table align="center" width="50%" cellpadding="2" cellspacing="1" border="0" bgcolor="#CCCCC0">
					<tr>
						<td colspan="5" class="titulocolumna" align="center"><bean:message key="menu.module.corn.future"/></td>
					</tr>
					<tr>
						<td style="text-align: right;" class="etiqueta">
							<fmt:message key="label.futurepurchase.query.periodFrom"/>:
						</td>
						<td style="text-align: center;" class="etiqueta_campo">
							<select name="fpsView.beginPeriodYear" class="campo_texto">
								<c:forEach items="${periodYears}" var="year">
									<c:choose>
										<c:when test="${year == bPeriodYear}">
											<option value="<c:out value="${year}"/>" selected="selected"><c:out value="${year}"/></option>
										</c:when>
										<c:otherwise>
											<option value="<c:out value="${year}"/>"><c:out value="${year}"/></option>
										</c:otherwise>
									</c:choose>
								</c:forEach>
							</select>
						</td>
						<td style="text-align: right;"  class="etiqueta">
							<fmt:message key="label.futurepurchase.query.periodTo"/>:
						</td>
						<td style="text-align: center;" class="etiqueta_campo">
							<select name="fpsView.endPeriodYear" class="campo_texto">
								<c:forEach items="${periodYears}" var="year">
									<c:choose>
										<c:when test="${year == ePeriodYear}">
											<option value="<c:out value="${year}"/>" selected="selected"><c:out value="${year}"/></option>
										</c:when>
										<c:otherwise>
											<option value="<c:out value="${year}"/>"><c:out value="${year}"/></option>
										</c:otherwise>
									</c:choose>
								</c:forEach>
							</select>
						</td>
						<td align="center" class="columnadatoPar">
							<input type="submit" value="<fmt:message key="label.common.query"/>"  class="boton"/>
						</td>
					</tr>
					<tr>
					 	<td style="text-align: right;" class="etiqueta">
							<fmt:message key="message.futurepurchase.customer"/>:		 
						</td>
						<td colspan="4" style="text-align: left;" class="etiqueta_campo">
						    &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<html:text style="width: 135px;" property="fpsView.clientDescription" styleClass="campo_texto" />
						</td>
					</tr>
					<tr>
					 	<td style="text-align: right;" class="etiqueta">
							<fmt:message key="message.futurepurchase.product"/>:		 
						</td>
						<td colspan="4" style="text-align: left;" class="etiqueta_campo">
						    &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<html:text style="width: 135px;" property="fpsView.productDescription" styleClass="campo_texto" />
						</td>
					</tr>
				</table>	
			</td>
		</tr>
		<tr>
			<td>
				<div style="background-color: #C0C0C0; border: .1px solid;"/>
			</td>
		</tr>
		<tr>
			<td>
				<table align="center" cellpadding="1" cellspacing="1" border="0" bgcolor="#CCCCC0" width="700">
					<tr>
						<td class="titulocolumna" align="center" width="20">
							<s:entidad nombreCortoMod="PROC" nombreCortoSub="FUTURES" nombreCortoEnt="NEW" permiso="ADMINISTRACION">
								<html:link action="/goFuturePurchaseByCustomer?new=Y"><img alt="<fmt:message key="common.add"/> <fmt:message key="label.purchase.program.futures"/>" src="images/nuevo.gif" border="0"></html:link>
							</s:entidad>
						</td>
						<td class="titulocolumna" align="center" width="20">&nbsp;</td>
						<td class="titulocolumna" align="center" width="100">
							<a href="#>" onclick="return submitCustomerFutureQuery(document.SearchFuturePurchaseForm, 0,'<c:choose><c:when test="${previousOrderField == 0 && previousOrderType == 0}">1</c:when><c:otherwise>0</c:otherwise></c:choose>');" class="ligas">
								<fmt:message  key="message.futurepurchase.customer"/>
								<c:choose>
									<c:when test="${previousOrderField == 0 && previousOrderType == 1}">
										<img alt="<bean:message key="label.common.order.ascending"/>" src="images/arrow_up.gif" border="0"/>
									</c:when>
									<c:when test="${previousOrderField == 0 && previousOrderType == 0}">
										<img alt="<bean:message key="label.common.order.descending"/>" src="images/arrow_down.gif" border="0"/>
									</c:when>
								</c:choose>
							</a>
						</td>
						
						<td class="titulocolumna" align="center"  width="250">		
							<a href="#>" onclick="return submitCustomerFutureQuery(document.SearchFuturePurchaseForm, 1,'<c:choose><c:when test="${previousOrderField == 1 && previousOrderType == 0}">1</c:when><c:otherwise>0</c:otherwise></c:choose>');" class="ligas">
								<fmt:message  key="message.futurepurchase.customer.description"/>
								<c:choose>
									<c:when test="${previousOrderField == 1 && previousOrderType == 1}">
										<img alt="<bean:message key="label.common.order.ascending"/>" src="images/arrow_up.gif" border="0"/>
									</c:when>
									<c:when test="${previousOrderField == 1 && previousOrderType == 0}">
										<img alt="<bean:message key="label.common.order.descending"/>" src="images/arrow_down.gif" border="0"/>
									</c:when>
								</c:choose>
							</a>
						</td>
						<td class="titulocolumna" width="310">
							<table width="100%" cellpadding="0" cellspacing="0" bgcolor="#CCCCC0" border="0">
								<tr>
									<td class="titulocolumna" align="center" width="7%">&nbsp;</td>
									<td class="titulocolumna" align="center" width="19%">
										<fmt:message key="label.customerfuturepurchase.applicationPeriod.shortName"/>
									</td>
									<td class="titulocolumna" align="center" width="19%">
										<fmt:message key="label.customerfuturepurchase.accountPeriod.shortName"/>
									</td>
									<td class="titulocolumna" align="center" width="8%">
										<fmt:message key="label.customerfuturepurchase.type.shortName"/>
									</td>
									<td class="titulocolumna" align="center" width="16%"><fmt:message key="label.futurepurchase.query.quantity"/></td>
									<td class="titulocolumna" align="center" width="24%">
										<fmt:message key="label.customerfuturepurchase.unitPrice.shortName"/>
									</td>
									<td class="titulocolumna" align="center" width="7%">&nbsp;</td>
								</tr>
							</table>
						</td>
					</tr>
					<c:forEach items="${customerFuturePurchases}" var="customerFuturePurchase" varStatus="colum">
						<tr class="<c:choose><c:when test="${colum.index%2 == 0}"><c:out value="columnadatoPar" /></c:when><c:otherwise><c:out value="columnadatoNon" /></c:otherwise></c:choose>">
							<td valign="top" align="center" width="20">&nbsp;</td>
							<td valign="top" align="center" width="20">
								<c:out value="${colum.index+1}"></c:out>
							</td>
							<td valign="top" width="100">
								<c:out value="${customerFuturePurchase.customerId}"/>
							</td>
							<td valign="top" width="250">
								<c:out value="${customerFuturePurchase.description}"/>
							</td>
							<td valign="top">
								<table width="310" cellpadding="1" cellspacing="0" bgcolor="#CCCCC0" border="0">
									<c:forEach items="${customerFuturePurchase.futurePurchases}" var="futurePurchase">
										<% 	java.util.HashMap mapa=new java.util.HashMap(0);%>
										<bean:define id="id" name="futurePurchase" property="cornFutureDistributionId"></bean:define>
										<% 	mapa.put("cornFutureDistributionId",id);
											request.setAttribute("mapa",mapa); 
										%>
										<tr class="<c:choose><c:when test="${colum.index%2 == 0}"><c:out value="columnadatoPar" /></c:when><c:otherwise><c:out value="columnadatoNon" /></c:otherwise></c:choose>">
											<td align="center" width="7%">
												<s:entidad nombreCortoMod="PROC" nombreCortoSub="FUTURES" nombreCortoEnt="EDIT" permiso="ADMINISTRACION">
													<html:link action="/goEditFuturePurchaseByCustomer" name="mapa"><img alt="<fmt:message key="common.edit"/> <c:out value="${futurePurchase.cornFutureDistributionId}"></c:out>" src="images/modificar.gif" border="0"></html:link>
												</s:entidad>
											</td>
											<td align="center" width="19%">
												<c:out value="${futurePurchase.accountFuturePeriodName}"/>
											</td>
											<td align="center" width="19%">
												<c:out value="${futurePurchase.applicationFuturePeriodName}"/>
											</td>
											<td align="center" width="8%">
												<c:out value="${futurePurchase.futureTypeId}"/>
											</td>
											<td align="center" width="16%">
												<c:out value="${futurePurchase.customerFutureQuantity}"/>
											</td>
											<td align="right" width="24%">
												<fmt:formatNumber pattern="###,###,###0.0000" value="${futurePurchase.unitPrice}"/>
											</td>
											<td align="center" width="7%">
												<s:entidad nombreCortoMod="PROC" nombreCortoSub="FUTURES" nombreCortoEnt="DELETE" permiso="ADMINISTRACION">
													<a href="#>" onclick="if(confirmDelete('<c:out value="${colum.index+1}"></c:out>'))location.href='deleteFuturePurchaseByCustomer.do?cornFutureId=<bean:write name="futurePurchase" property="futurePurchaseId"/>&cornFutureDistributionId=<bean:write name="id"/>';">
														<img alt="<bean:message key="common.delete"/> <c:out value="${colum.index+1}"></c:out>" src="images/eliminar.jpg" border="0">
													</a>
												</s:entidad>
											</td>
										</tr>
									</c:forEach>
								</table>
							</td>
						</tr>
					</c:forEach>
				</table>
			</td>
		</tr>
	</table>
</html:form>